﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileMonitor.Configuration.Tool.Controls.Prototype;
namespace FileMonitor.Configuration.Tool.Controls
{
    public partial class CSharpProcessEditor :ProcessEditorBase
    {
        public CSharpProcessEditor()
            : base()
        {
            InitializeComponent();
            this.txt_ProcessName.Text = "CSharp_";
            this.txt_ProcessName.TextChanged += new EventHandler(txt_ProcessName_TextChanged);
            this.txt_TimeOut.TextChanged += new EventHandler(txt_TimeOut_TextChanged);
            this.txt_NextStatus.TextChanged += new EventHandler(txt_NextStatus_TextChanged);
        }
     

        public void BindTypeList(List<string> list)
        {
            this.box_TypeName.DataSource = list;
        }

        public void BindDatabaseList(List<string> list)
        {
            this.box_TargetDatabaseName.DataSource = list.ToArray() ;
            this.box_SourceDatabaseName.DataSource = list;
        }

        void txt_ProcessName_TextChanged(object sender, EventArgs e)
        {
            string text = this.txt_ProcessName.Text;
            if (!text.StartsWith("CSharp_"))
            {
                MessageBox.Show("Process Name have to start with 'Procedure_'");
                IsCanbeSaved = false;
            }
            else
            {
                IsCanbeSaved = true;
            }
        }
        void txt_NextStatus_TextChanged(object sender, EventArgs e)
        {
            string status = this.txt_NextStatus.Text;
            int i = 0;
            if (!Int32.TryParse(status, out i))
            {
                this.lblNextStatuError.Visible = true;
                base.IsCanbeSaved = false;
            }
            else
            {
                this.lblNextStatuError.Visible = false;
                base.IsCanbeSaved = true;
            }
        }

        void txt_TimeOut_TextChanged(object sender, EventArgs e)
        {
            string timeOut = this.txt_TimeOut.Text;
            int i = 0;
            if (!Int32.TryParse(timeOut, out i))
            {
                this.lblTimeOutError.Visible = true;
                base.IsCanbeSaved = false;
            }
            else
            {
                this.lblTimeOutError.Visible = false;
                base.IsCanbeSaved = true;
            }
        }

    }
}
